﻿@model Object
@using System.ComponentModel;
@using System.Reflection;
@using NewLife.Cube;
@using NewLife.Reflection;
@using XCode.Membership
@{
    Layout = NewLife.Cube.Setting.Current.Layout;

    var Obj = Model as Object;
    var pis = ViewBag.Properties as IEnumerable<PropertyInfo>;
}

<div class="m-portlet m-portlet--last m-portlet--responsive-mobile m-portlet--sticky">
    <div class="m-portlet__body">
        <div class="row">
            @Html.Partial("_Object_Nav", Model)
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="form-horizontal">
                    @using (Html.BeginForm("Update", null))
                    {
                        @Html.AntiForgeryToken()
                        @Html.ValidationSummary(true)
                        foreach (var pi in pis)
                        {
                            var name = pi.Name;
                            var dis = pi.GetDisplayName();
                            var des = pi.GetDescription();
                            if (dis.IsNullOrEmpty() && !des.IsNullOrEmpty()) { dis = des; des = null; }
                            if (!dis.IsNullOrEmpty() && des.IsNullOrEmpty() && dis.Contains("。"))
                            {
                                des = dis.Substring("。");
                                dis = dis.Substring(null, "。");
                            }

                            <div class="cube-flex-con" style="margin-bottom: 10px; width: 100%; min-height: 3rem;">
                                <div class="col-xs-2 col-md-4 col-xs-2 col-md-4 cube-flex-con cube-flex-items cube-flex-end" style="padding: 0;">
                                    <label class="control-label no-padding-left" for="@pi.Name" style="text-align: right; padding: 0;">@(dis ?? pi.Name)</label>
                                    <div class="m--margin-right-5 m--margin-left-5 cube-flex-con cube-flex-items" style="width:18px;">
                                        @if (!des.IsNullOrEmpty())
                                        {
                                            <i class="la la-question-circle" data-skin="light" data-toggle="m-popover" data-placement="top" title="" data-content="@des" style="margin-top: 4px;"></i>
                                        }
                                    </div>
                                </div>
                                <div class="input-group col-xs-10 col-md-4 cube-flex-con cube-flex-items" style="padding: 0;">
                                    @Html.ForEditorX(pi.Name, Obj.GetValue(pi), pi.PropertyType, null, new { @class = "form-control form-control-sm m-input" }.ToDictionary())
                                    @Html.ValidationMessage(pi.Name)
                                </div>
                            </div>                            
                        }
                        if (this.Has(PermissionFlags.Update))
                        {
                            <div class="clearfix form-actions col-sm-12 col-md-12">
                                <label class="control-label col-xs-4 col-sm-5 col-md-5"></label>
                                <button type="submit" class="btn btn-success"><i class="la la-save"></i><strong>保存</strong></button>
                                <button type="button" class="btn btn-danger" onclick="history.go(-1);"><i class="la la-remove"></i><strong>取消</strong></button>
                            </div>
                        }
                    }
                </div>
            </div>
        </div>
    </div>
</div>

